<template>
  <div class="page">
    <div class="s-search p20">
      <el-form
        :model="alone.searchForm.data"
        status-icon
        ref="ruleForm"
        :inline="true"
        class="demo-ruleForm"
      >
        <el-form-item>
          <el-input
            placeholder="请输入昵称/微信号搜索"
            v-model="alone.searchForm.data.searchStr"
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="alone.searchForm.data.signWish"
            placeholder="请选择签约意愿搜索"
          >
            <el-option
              v-for="item in $store.state.SIGN.WISH.list"
              :key="item.value"
              :label="item.name"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="alone.searchForm.data.platform"
            placeholder="请选择意向平台搜索"
          >
            <el-option
              v-for="item in $store.state.platformList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="rSubmitSearchForm">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="c-main p20">
      <div class="c-aside clearfix">
        <el-button
          type="primary"
          class="fr btn"
          @click="rToUrl"
          v-hasAuth:seestar_create
          >新增</el-button
        >
      </div>
      <div class="c-section">
        <div class="c-body">
          <el-table :data="pageAjax.data" stripe style="width: 100%">
            <el-table-column label="头像" width="130">
              <template slot-scope="scope">
                <el-image
                  class="c-avatar"
                  :src="scope.row.avatarUrl"
                  fit="cover"
                ></el-image>
              </template>
            </el-table-column>
            <el-table-column prop="nickName" label="昵称">
              <template slot-scope="scope">
                <div class="">
                  {{
                    scope.row.nickName +
                      (!scope.row.hasLiveExperience ? "(素人)" : "") || "无"
                  }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="微信号">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.wxNo || "无" }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="联系电话">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.contractPhone || "无" }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="来源">
              <template slot-scope="scope">
                <div class="">
                  <span v-if="scope.row.source === 0">
                    <template v-if="scope.row.onlineType == 'ONLINE'">
                      线上
                    </template>
                    <template v-else>
                      线下{{
                        scope.row.channelName
                          ? "(" + scope.row.channelName + ")"
                          : ""
                      }}
                    </template>
                  </span>
                  <span v-else-if="scope.row.source === 1">
                    星探{{
                      scope.row.scoutName ? "(" + scope.row.scoutName + ")" : ""
                    }}
                  </span>
                  <span v-else>
                    联营{{
                      scope.row.unionName ? "(" + scope.row.unionName + ")" : ""
                    }}
                  </span>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="意向平台">
              <template slot-scope="scope">
                <div class="text-abbreviate">
                  {{ scope.row.intentionPlatform || "无" }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="期望待遇">
              <template slot-scope="scope">
                <div class="">
                  {{
                    getSalaryStr(
                      scope.row.expectedBaseSalary,
                      scope.row.expectedBottomGuard,
                      scope.row.expectedSigningBonus,
                      scope.row.expectedOther
                    ) || "无"
                  }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="签约意愿">
              <template slot-scope="scope">
                <div class="">
                  {{
                    $store.state.SIGN.WISH.translate[scope.row.signWish] || "无"
                  }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="签约状态">
              <template slot-scope="scope">
                <div class="">
                  {{
                    $store.state.SIGN.STATUS.translate[scope.row.signStatus] ||
                      "无"
                  }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="150">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  v-hasAuth:seestar_detail
                  @click="navToDetail(scope.row.anchorId)"
                  >详情</el-button
                >
                <el-button
                  type="text"
                  size="small"
                  v-hasAuth:seestar_edit
                  @click="navToEdit(scope.row.anchorId)"
                  >修改</el-button
                >
                <el-button
                  type="text"
                  size="small"
                  v-hasAuth:seestar_delete
                  @click="rDeleteActor(scope.row.anchorId)"
                  >删除</el-button
                >
                <el-button
                  type="text"
                  size="small"
                  v-hasAuth:seestar_pageView
                  @click="getPageView(scope.row)"
                  >浏览记录</el-button
                >
                <span
                  v-hasAuth:seestar_detail-seestar_edit-seestar_pageView-seestar_delete.invert
                  >—</span
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="c-footer">
          <div class="c-pagination">
            <el-pagination
              layout="prev, pager, next"
              @current-change="rPagingChange"
              @prev-click="rPagingChange"
              @next-click="rPagingChange"
              :current-page="pageAjax.paging.current"
              :total="pageAjax.paging.total"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
    <!-- 浏览记录 -->
    <el-drawer :visible.sync="pageView.visible" direction="ttb" size="700px">
      <div class="f-record">
        <el-row class="">
          <el-col :span="18" :offset="3">
            <div class="c-main">
              <el-table :data="pageView.list" style="width: 100%" height="500">
                <el-table-column label="头像" width="150">
                  <template slot-scope="scope">
                    <el-image
                      class="c-avatar"
                      :src="scope.row.userView.avatarUrl"
                      fit="cover"
                    ></el-image>
                  </template>
                </el-table-column>
                <el-table-column label="昵称">
                  <template slot-scope="scope">
                    {{ scope.row.userView.nickName }}
                  </template>
                </el-table-column>
                <el-table-column prop="followUp" label="姓名">
                  <template slot-scope="scope">
                    {{ scope.row.userView.realName }}
                  </template>
                </el-table-column>
                <el-table-column prop="followUp" label="部门">
                  <template slot-scope="scope">
                    {{ scope.row.userView.departmentName }}
                  </template>
                </el-table-column>
                <el-table-column prop="userAgent" label="负责的平台">
                  <template slot-scope="scope">
                    {{ scope.row.userView.platformName }}
                  </template>
                </el-table-column>
                <el-table-column prop="userAgent" label="浏览方式">
                </el-table-column>
                <el-table-column prop="createTime" label="浏览时间" width="180">
                </el-table-column>
              </el-table>
              <div class="c-footer">
                <div class="c-pagination">
                  <el-pagination
                    layout="prev, pager, next"
                    @current-change="getPageViewData"
                    :current-page="pageView.pageNo"
                    :total="pageView.total"
                  >
                  </el-pagination>
                </div>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </el-drawer>
  </div>
</template>
<script>
import pageViewMixin from "./mixin";
import { getActorList, deleteActor } from "@/api/actor.js";
import { mixin } from "@/components/mixin/getSalaryStr.js";
import _ from "lodash";
export default {
  name: "list",
  mixins: [mixin, pageViewMixin],
  data: () => ({
    pageAjax: {
      btnDisabled: false,
      btnLoading: false,
      loading: false,
      lock: false,
      paging: {
        pages: 1, // 总页数
        current: 0, // 当前页
        total: 1, // 总数量
        pageSize: 10 // 每页数量
      },
      data: []
    },
    alone: {
      searchForm: {
        loading: false,
        data: {
          searchStr: "",
          signWish: "",
          platform: "",
          relType: 0
        }
      }
    }
  }),
  created() {
    let _that = this;
    _that.getPageData();
  },
  methods: {
    rSubmitSearchForm() {
      let _that = this;
      let searchForm = _that.alone.searchForm;
      if (searchForm.loading) {
        return;
      }
      _that.alone.searchForm.loading = true;
      // if (!searchForm.data.searchStr && !searchForm.data.signWish && !searchForm.data.platform) {
      //   _that.$message.error({message: "搜索条件不能都为空", onClose: () => {
      //     _that.alone.searchForm.loading = false;
      //   }});
      //   return;
      // }
      _that.pageAjax.lock = false;
      _that.pageAjax.paging.current = 0;
      _that.getPageData();
    },
    rPagingChange(e) {
      let _that = this;
      _that.pageAjax.paging.current = e - 1;
      _that.getPageData();
    },
    getPageData() {
      let _that = this;
      let searchForm = _.cloneDeep(_that.alone.searchForm);
      let pageAjax = _that.pageAjax;

      if (pageAjax.loading || pageAjax.lock) {
        return;
      }

      let data = { ...searchForm.data };
      data.pageNo = _that.pageAjax.paging.current + 1;
      _that.pageAjax.loading = true;
      getActorList({ params: data })
        .then(resp => {
          let respData = resp.data || {};

          if (respData.code === _that.STATUS.success[0]) {
            _that.pageAjax.data = respData.data.list;
            _that.pageAjax.paging = {
              pages: respData.data.pagination.pages,
              current: respData.data.pagination.current,
              total: respData.data.pagination.total,
              pageSize: respData.data.pagination.pageSize
            };
          } else {
            _that.$message.error(respData.msg || "获取失败");
          }
        })
        .finally(() => {
          _that.pageAjax.loading = false;
          _that.alone.searchForm.loading = false;
        });
    },
    rDeleteActor(id) {
      let _that = this;
      this.$confirm("你确定要删除此数据?", "删除提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          deleteActor({ anchorId: id }).then(resp => {
            let respData = resp.data || {};

            if (respData.code === _that.STATUS.success[0]) {
              _that.pageAjax.paging.current =
                _that.pageAjax.paging.current > 0
                  ? _that.pageAjax.paging.current - 1
                  : 0;
              _that.$message.success(respData.msg || "删除成功");
              _that.getPageData();
            } else {
              _that.$message.error(respData.msg || "删除失败");
            }
          });
        })
        .catch(() => {});
    },
    rToUrl() {
      this.$router.push({ name: "seestar_create" });
    },
    navToEdit(id) {
      this.$router.push({
        name: "seestar_edit",
        query: {
          anchorId: id
        }
      });
    },
    navToDetail(id) {
      this.$router.push({
        name: "seestar_detail",
        query: {
          anchorId: id
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.page {
  .s-search {
    border-bottom: 1px solid #eee;
  }
  .c-aside {
    .btn {
      margin-right: 20px;
    }
    .diy-uploadBtn {
      margin-right: 20px;
    }
  }
  .c-main {
    margin-top: 20px;
    .c-avatar {
      display: block;
      width: 100px;
      height: 100px;
      border-radius: 50%;
    }
  }
  .c-pagination {
    margin-top: 20px;
    text-align: center;
  }
}
</style>
